import React, { Component } from 'react'
import axios from 'axios'   //导入axios(npm install axios)

class Apps extends Component{
    state={
        info:[]
    }
    handle=async ()=>{
        let url="https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata"
        let ret=await axios.get(url);
        this.setState({
            info:ret.data.message
        })
    }
    render(){
        return(
            <div>
                <h3>测试Axios请求</h3>
                <button onClick={this.handle}>发Ajax请求</button>
                {
                    this.state.info.map((item)=>{
                        return(
                        <p key={item.goods_id}>
                            <span>{item.goods_id}</span>
                            <img width="100px" src={item.image_src} />
                        </p>
                        )
                    })

                }
            </div>
        )
    }
}
export default Apps